<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1></h1>
<script>
  let h=document.querySelector("h1");
  let count=0;
  //           间隔时间（单位：毫秒）
  setInterval(f,1000);

  let timer = setInterval(function () {
    if (count==50){
      clearInterval(timer);
    }
    console.log(count);
  },1000)
  setTimeout(function () {
      alert("时间到")
  },3000)
  function f(){
    count++
    h.innerText=count;
  }

</script>

</body>
</html>